package com.yinile.zc03.web;

import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.yinile.zc03.sys.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.yinile.zc03.service.BookService;
import com.yinile.zc03.domain.Book;

/**
 * 书的控制器
 */
@RestController
@RequestMapping("/book")
@Api(description="Book，书相关")
public class BookController {
	@Autowired
	BookService bookService;
	
	@ApiOperation(value = "书详情", notes = "书详情", 
			produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public BaseResult get(@PathVariable String id){
		return this.bookService.findOne(id);
	}
	
	@ApiOperation(value = "删除书", notes = "删除书", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public BaseResult delete(@PathVariable String id){
		return this.bookService.delete(id);
	}
	
	@ApiOperation(value = "保存书", notes = "保存书", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="",method=RequestMethod.POST)
	public BaseResult save(@RequestBody Book book){
		return this.bookService.save(book);
	}
	
	@ApiOperation(value = "更新作者", notes = "更新作者", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	@RequestMapping(value="",method=RequestMethod.PUT)
	public BaseResult update(@RequestBody Book book){
		return this.bookService.update(book);
	}
}
